import React, { useState} from 'react';
// import ImgCrop from 'antd-img-crop';
// import { Form, Input, Upload, Button } from 'antd';
const UploadImg = (props) => {
    const {initUrl,id}=props
    const [fileList, setFileList] = useState(initUrl?[
        {
          uid: '-1',
          name: 'image.png',
          status: 'done',
          url: initUrl,
        },
   ]:[]);
    const imgChange = ({ fileList: newFileList }) => {
        console.log(newFileList)
        setFileList(newFileList);
    };
    const onPreview = async file => {
        let src = file.url;
        if (!src) {
            src = await new Promise(resolve => {
                const reader = new FileReader();
                reader.readAsDataURL(file.originFileObj);
                reader.onload = () => resolve(reader.result);
            });
        }
        const image = new Image();
        image.src = src;
        const imgWindow = window.open(src);
        imgWindow.document.write(image.outerHTML);
    };
    return (
        <div>
            {/* <ImgCrop rotate>
                <Upload
                    action="/api/uploadimg"
                    listType="picture-card"
                    fileList={fileList}
                    onChange={imgChange}
                    onPreview={onPreview}
                >
                    {fileList.length < 1 && '+ Upload'}
                </Upload>
            </ImgCrop> */}
        </div>
    );
}

export default UploadImg;
